package entity;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

public class ShootingEntity extends Entity{

	protected Bullet bullet;
	public boolean shoot = false;
	
	float damage;
	float attackSpeed;
	float attackTime = 0;
	boolean canAttack = false;
	
	Vector2f direction;
	
	float attackAccuracy;

	boolean animate = false;
	
	public ShootingEntity(Vector2f position) {
		super(position);
		// TODO Auto-generated constructor stub
	}
	
	public void update(GameContainer container, int delta) throws SlickException
	{			

	}
	protected boolean canShoot() {
		if(!canAttack)
		{
			attackTime++;
			if(attackTime > 100 - attackSpeed * 8)
			{
				attackTime = 0;
				canAttack = true;
				return true;
			}
			return false;
		}
		return true;
	}
	protected float calculatePrecision()
	{
		double precision =  Math.random() * (11 - attackAccuracy);
		if(Math.random() > 0.5)
			return (float) -precision;
		else
			return (float) precision;
	}
	protected void shoot(Vector2f target, boolean isHero)
	{
		target.add(calculatePrecision());
		bullet = new Bullet(new Vector2f(position), target , damage, isHero);
		shoot = true;		
	}
	public Bullet shoot()
	{
		shoot = false;
		return bullet;
	}
	public void update(float damage, float attackSpeed, float attackAccuracy)
	{
		this.damage = damage;
		this.attackSpeed = attackSpeed;
		this.attackAccuracy = attackAccuracy;
	}
	public void setDirection(Vector2f d)
	{
		direction = d.sub(position).normalise();
	}

}
